package com.dhcc.wb.gongzhonghao;

import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.dhcc.bussiness.page.PageBean;
import com.dhcc.common.util.StringUtil;
import com.dhcc.wb.qiye.QiyeDao;
import com.dhcc.wb.qiye.QiyeModel;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class GzhAction extends ActionSupport {
	private static final long serialVersionUID = 1L;
	private static Logger logger = Logger.getLogger(ActionSupport.class);
	
	
	private GzhDao dao = new GzhDao();
	private QiyeDao qiyedao = new QiyeDao();
	
	private Integer currentPage;
	private Integer currentCount = 10;
	private PageBean<GzhModel> pageBean = new PageBean<GzhModel>();
	private GzhService service = new GzhService();
	
	private String _id;
	private String result;
	private GzhModel gzh;
	
	private String gzhid;//
    private String gzhname;//
    private String appid;//
    private String secret;//
    private String qiyeid;//
    private String qiyename;//
    private String beizhu;//
	
	
	public String gzh() throws Exception {
		// TODO Auto-generated method stub
		
		HttpServletRequest request = ServletActionContext.getRequest();
		int currentPage = Integer.parseInt(request.getParameter("currentPage")==null?"1":request.getParameter("currentPage"));//规定是第一页
		String name = request.getParameter("name");
		pageBean = service.findQiyeServiceByPage(currentPage,currentCount,name);
		ActionContext.getContext().getSession().put("pageBean", pageBean);
		return SUCCESS;
	}
	
	public String delete() throws Exception {
		// TODO Auto-generated method stub
		int i = dao.delete(_id);
		if(i>0){
			result = "success";
		}
		return SUCCESS;
	}

	public String edit() throws Exception {
		// TODO Auto-generated method stub
		gzh = dao.queryqiye_result(_id);
		ActionContext.getContext().getSession().put("qiyeAll", qiyedao.getAll());
		ActionContext.getContext().getSession().put("gzh", gzh);
		return SUCCESS;
	}
	
	public String save() throws Exception {
		// TODO Auto-generated method stub
		
//		
		QiyeDao dao1 = new QiyeDao();
		QiyeModel ent = dao1.queryqiye_result(qiyeid);
		
		String qiyename = (ent != null && !StringUtil.isNullOrEmpty(ent.getQiyename()))?ent.getQiyename():"";
		
		
	    if(!StringUtil.isNullOrEmpty(gzhid)){
	    	dao.updateGzhEnt(gzhid, gzhname, appid, secret, qiyeid, beizhu,qiyename);
	    }else{
	    	dao.addGzh(UUID.randomUUID().toString(), gzhname, appid, secret, qiyeid, beizhu,qiyename);
	    }
	    
		return SUCCESS;
	}

	public Integer getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}

	public Integer getCurrentCount() {
		return currentCount;
	}

	public void setCurrentCount(Integer currentCount) {
		this.currentCount = currentCount;
	}

	public String get_id() {
		return _id;
	}

	public void set_id(String _id) {
		this._id = _id;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public GzhModel getGzh() {
		return gzh;
	}

	public void setGzh(GzhModel gzh) {
		this.gzh = gzh;
	}

	public String getGzhid() {
		return gzhid;
	}

	public void setGzhid(String gzhid) {
		this.gzhid = gzhid;
	}

	public String getGzhname() {
		return gzhname;
	}

	public void setGzhname(String gzhname) {
		this.gzhname = gzhname;
	}

	public String getAppid() {
		return appid;
	}

	public void setAppid(String appid) {
		this.appid = appid;
	}

	public String getSecret() {
		return secret;
	}

	public void setSecret(String secret) {
		this.secret = secret;
	}

	public String getQiyeid() {
		return qiyeid;
	}

	public void setQiyeid(String qiyeid) {
		this.qiyeid = qiyeid;
	}

	public String getBeizhu() {
		return beizhu;
	}

	public void setBeizhu(String beizhu) {
		this.beizhu = beizhu;
	}

	public String getQiyename() {
		return qiyename;
	}

	public void setQiyename(String qiyename) {
		this.qiyename = qiyename;
	}




	
}
